package org.wesc.boot.common.utils;

import org.apache.commons.beanutils.BeanMap;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Wesley
 */
public class BeanUtil {

    /**
     * 实体类非空属性转map
     *
     * @param object 实体类
     */
    public static Map<String, Object> beanToMap(Object object) {
        // 构造查询条件
        Map<String, Object> params = new HashMap<>(16);
        for (Map.Entry<Object, Object> e : new BeanMap(object).entrySet()) {
            if (null != e.getValue()) {
                params.put((String) e.getKey(), e.getValue());
            }
        }
        return  params;
    }

}
